﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Logistics.Utils
{
    class StringUtils
    {
        /// <summary>
        /// 正则去除汉字和只取汉字
        /// </summary>
        /// <param name="oriStr"></param>
        /// <param name="flag">1:只取汉字；2:只取数字;3:去除汉字</param>
        /// <returns></returns>
        public static string GetNumberFromString(string oriStr, int flag)
        {
            string desStr = string.Empty;
            if (flag == 1)//只取汉字
                desStr = System.Text.RegularExpressions.Regex.Replace(oriStr, @"[^\u4e00-\u9fa5]", "");
            else if (flag == 2)//只取数字
                desStr = System.Text.RegularExpressions.Regex.Replace(oriStr, @"\D", "");
            else if (flag == 3)//去除汉字
                desStr = System.Text.RegularExpressions.Regex.Replace(oriStr, @"[\u4e00-\u9fa5]", "");
            return desStr;
        }

        //验证是否为电话号码
        public static bool IsValidTel(string strIn)
        {
            return Regex.IsMatch(strIn, @"(^[0-9]{3,4}\-[0-9]{7,8}$)|(^[0-9]{7,8}$)|(^[0-9]{3,4}[0-9]{7,8}$)|(^\([0-9]{3,4}\)[0-9]{7,8}$)");
        }
        //验证是否为手机号码
        public static bool IsValidCellPhoneNumer(string str_handset)
        {
            return Regex.IsMatch(str_handset, @"^[1]+[3,5,8]+\d{9}");
        }
    }
}
